package com.yh.csx.bsf.flow.dao.dal.auto;


import com.yh.csx.bsf.flow.core.db.DbConn;
import com.yh.csx.bsf.core.util.ConvertUtils;
import com.yh.csx.bsf.flow.dao.model.auto.t_user_model;
import lombok.val;

import java.util.ArrayList;
import java.util.Date;
import java.util.Map;

/**
 * t_user 表自动dal映射,不要手工修改
 * 用户表
 *
 * @author 车江毅
 * @since 2021-01-12 17:50:53
 * 自动生成: https://gitee.com/makejava/EasyCode/wikis/
 */
public class t_user_base_dal {

    public boolean add(DbConn conn, t_user_model model) {
        val par = new Object[]{
                /**唯一标识*/
                model.no,
                /**名称*/
                model.name,
                /**手机*/
                model.mobile,
                /**邮箱*/
                model.email,
                /**备注*/
                model.remark,
                /**创建时间*/
                model.create_time,
                /**更新时间*/
                model.update_time
        };
        int rev = conn.executeSql("insert into t_user(no,name,mobile,email,remark,create_time,update_time)" +
                "values(?,?,?,?,?,?,?)", par);
        return rev == 1;
    }

    public boolean edit(DbConn conn, t_user_model model) {
        val par = new Object[]{
                /**唯一标识*/
                model.no,
                /**名称*/
                model.name,
                /**手机*/
                model.mobile,
                /**邮箱*/
                model.email,
                /**备注*/
                model.remark,
                /**创建时间*/
                model.create_time,
                /**更新时间*/
                model.update_time,
                model.id
        };
        int rev = conn.executeSql("update t_user set no=?,name=?,mobile=?,email=?,remark=?,create_time=?,update_time=? where id=?", par);
        return rev == 1;

    }

    public boolean delete(DbConn conn, Integer id) {
        val par = new Object[]{id};
        String Sql = "delete from t_user where id=?";
        int rev = conn.executeSql(Sql, par);
        return rev == 1;
    }

    public t_user_model get(DbConn conn, Integer id) {
        val par = new Object[]{id};
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from t_user s where s.id=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return createModel(ds.get(0));
        }
        return null;
    }

    public ArrayList<t_user_model> list(DbConn conn) {
        val rs = new ArrayList<t_user_model>();
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from t_user s ");
        val ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0) {
            for (Map<String, Object> dr : ds) {
                rs.add(createModel(dr));
            }
        }
        return rs;
    }

    public t_user_model createModel(Map<String, Object> dr) {
        val o = new t_user_model();
        /***/
        if (dr.containsKey("id")) {
            o.id = ConvertUtils.convert(dr.get("id"), Integer.class);
        }
        /**唯一标识*/
        if (dr.containsKey("no")) {
            o.no = ConvertUtils.convert(dr.get("no"), String.class);
        }
        /**名称*/
        if (dr.containsKey("name")) {
            o.name = ConvertUtils.convert(dr.get("name"), String.class);
        }
        /**手机*/
        if (dr.containsKey("mobile")) {
            o.mobile = ConvertUtils.convert(dr.get("mobile"), String.class);
        }
        /**邮箱*/
        if (dr.containsKey("email")) {
            o.email = ConvertUtils.convert(dr.get("email"), String.class);
        }
        /**备注*/
        if (dr.containsKey("remark")) {
            o.remark = ConvertUtils.convert(dr.get("remark"), String.class);
        }
        /**创建时间*/
        if (dr.containsKey("create_time")) {
            o.create_time = ConvertUtils.convert(dr.get("create_time"), Date.class);
        }
        /**更新时间*/
        if (dr.containsKey("update_time")) {
            o.update_time = ConvertUtils.convert(dr.get("update_time"), Date.class);
        }
        return o;
    }
}